$(function () {
    obj.init();
});

var obj = new function JsFun() {
    return {
        dataGrid: null,
        init: function () {
            this.dataGrid = new xhDataGrid($('#list'), 'Device/getRepairDeviceInfo', {userId: xhTool.getQuery('userId')});
            this.dataGrid.parseToolbar().init().activeButton([], ['bt_list_history', 'bt_list_commit']);
            xhExtra.clearLoadSuccess(this.dataGrid);
            this.listener();
        },
        listener: function () {
            var $this = this;
            var dataGrid = $('.xh-datagrid');
            //查看检测报告
            dataGrid.on('click','.checkReport',function () {
                var reportUrl=$(this).attr('reportUrl');
                window.top.xhTop.showModal({
                    width:'800',
                    title:'查看检测报告',
                    content: '<img style="max-width:100%" src="'+reportUrl+'" alt="无检测报告数据">'
                });
            });
            //查看收费票据
            dataGrid.on('click','.document',function () {
                var documentUrl=$(this).attr('documentUrl');
                window.top.xhTop.showModal({
                    width:'800',
                    title:'查看收费票据',
                    content: '<img style="max-width:100%" src="'+documentUrl+'" alt="无收费票据数据">'
                });
            });
            //查看故障详情
            dataGrid.on('click','.sRemark',function () {
                var sRemark = $(this).attr('sRemark');
                window.top.xhTop.showMessage({
                    title: '[故障详情]',
                    text: sRemark
                });
            });
            //沟通记录
            $('#bt_list_commit').click(function(){
                if(xhExtra.buttonDisabled($(this))) return false;
                $this.funObj().commData();
            });
            //流程记录
            $('#bt_list_history').click(function(){
                if(xhExtra.buttonDisabled($(this))) return false;
                $this.funObj().history();
            });
        },
        funObj: function () {
            var $this = this;
            return {
                //历史记录
                history: function () {
                    var id = $this.dataGrid.getSelectValue('iId');
                    var sUserName = $this.dataGrid.getSelectValue('sUserName');
                    var sModel = $this.dataGrid.getSelectValue('sModel');
                    var sDeviceNumber = $this.dataGrid.getSelectValue('sDeviceNumber');
                    var sBrand = $this.dataGrid.getSelectValue('sBrand');
                    if (id === null) {
                        window.top.xhTop.showError('未选中记录！');
                        return false;
                    }
                    window.top.xhTop.showModal({
                        title: '操作记录:'+sUserName+'-'+sModel+'-'+sDeviceNumber+'-'+sBrand,
                        content: xhTool.getFrameString('Device/repairHandleList', {id:id}, 500),
                        size: 'lg',
                        width:'800'
                    });
                },
                commData: function () {
                    var id = $this.dataGrid.getSelectValue('iId');
                    var sDeviceNumber = $this.dataGrid.getSelectValue('sDeviceNumber');
                    if (!id) {
                        window.top.xhTop.showError('未选中记录！');
                        return false;
                    }
                    window.top.xhTop.showModal({
                        title: '设备' + sDeviceNumber + '沟通记录：',
                        content: xhTool.getFrameString('Device/getCommHistory', {id: id}, 500),
                        size: 'md',
                        button: true
                    });
                }
            }
        }
    }
};